<?php

namespace App\Exceptions;

use Exception;

class  ApiException extends \Exception
{
    const ERROR_CODE = 1001;
    const ERROR_MESSAGE = "ApiException";

    private $data = [];

    public function __construct(string $message, string $code, $data = [])
    {
        $this->code = $code ?? self::ERROR_CODE;
        $this->message = $message ?? self::ERROR_MESSAGE;
        $this->data = $data;
    }

    public function getData()
    {
        return $this->data;
    }

    public function render($request)
    {
        return response()->json([
            'data' => $this->getData(),
            'code' => $this->getCode(),
            'message' => $this->getMessage()
        ], 200);
    }
}